Fix 1208#1218
Conversation
The goal here is to make "nj_max" accessible at the level of the controlling Python script. The approach is to add a Sapporo Light function that will return "nj_max", next add a PH4 function that can call this function and, subsequentlty, provide a Python interface to this function, i.e. a layered approach.
According to the AMUSE guideline https://amuse.readthedocs.io/en/latest/tutorial/legacy_code.html we should be able to leave "src/amuse_ph4/interface.cc" untouched, i.e. exactly the same as in the "main" branch. I.e., this code should not be necessary.
In "sapporoG6lib.cpp" we can do "return grav.get_nj_max()" since that has "sapporo grav;".
This compiles, i.e.
"./setup install sapporo_light" and "./setup install amuse-ph4" will complete without error.
However, Erwan's script with an additional "print(f"{code.get_nj_max() = }, ")" will yield
"
TypeError: ph4Interface.get_nj_max() takes 0 positional arguments but 1 was given
"
LourensVeen
left a comment
There was a problem hiding this comment.
This should fix the 0 positional argoments error at least.
This function definition does not need to be separated.
1) 'extern "C"' not needed here 2) We need to adhere to AMUSE standards, I guess the legacy decorator implies that we need to set an argument 'int * value' and '*value = jd->get_nj_max(); return 0;' or we will be returned an empty list instead of an integer. 3) As a consequence of 2) we need to add an argument to the function: 'function.addParameter(...'.
"interface.cc" should have been added as part of the previous commit.
Essential is the '#ifdef GPU', since, when one executes "./setup install amuse-ph4" one will not link with Sapporo as one would when executing "./setup install amuse-ph4-sapporo". So "GPU" and "Sapporo" go hand in hand and one needs to make sure that "./setup install amuse-ph4" will complete without error when no GPU is available.
|
@LourensVeen with these recent commits, this will build and run, i,.e. if one adds a line to Erwan's script after the line it will print 131072, which means that the user gets to know the maximum number of stars that Sapporo Light allows for and adjust his/her Python script accordingly. Closes #1208 |
In the sense that the user has access to But when running a simulation with |
LourensVeen
left a comment
There was a problem hiding this comment.
Looks good, but I have a few small changes to request. Thanks!
Following@LourensVeen recommendation to prevent things from going wrong when there's a header include loop.
Following @LourensVeen's recommendation: When running PH4 simulations on a CPU instead of a GPU, Sapporo Light's "nj_max" does not play a role, so one will want to return a different very large number indicating the maximum number of stars allowed for the simulation. In case the number of stars in a simulation running on a CPU will approach "nj_max = std::numeric_limits<int>::max();" one will probably run into a memory error, but that's another matter.
This print statement should be displayed in the terminal where the controlling Python script is executed if "redirection=none" has been added as an argument to, e.g., ph4.
1) An error in deploying Sapporo Light only occurs if "nj > nj_max", i.e. strictly larger. 2) Extra blank line.
This has now been fixed, i.e. if the Python script has a line then there will be a line in the |
LourensVeen
left a comment
There was a problem hiding this comment.
One more comment but then this is ready to merge.
Addressing comment amusecode#1218 (comment) from @LourensVeen: " No need for #ifdef __cplusplus here, this file has a class in it so it must always be compiled with a C++ compiler, a C compiler is going to error anyway. "
"test7" is a unit test asserting that two parallel calls to a one second sleep should together takes less than two seconds. Apparently, this frequently fails on MacOS runners (@LourensVeen, private communication). Therefore, it seems better to bypass this test for that platform.
|
Codacy Static Code Analysis is complaining about an unused function, i.e. the but that complaint does not make sense to me, nor does the other complaint - |
LourensVeen
left a comment
There was a problem hiding this comment.
Looks good, let's merge this!
|
I think the unused function warning Codacy givesmay be about the I'm not sure though, and this is reported so spectacularly poorly that I suggest we leave it as is if only out of spite. |
Okay, but is not part of this MR and |
|
Hey Hanno! I appreciate you working on this, but I am not sure if it is completely fixed. After several trials, I built from commit 8dd292c and applied your original fix manually by changing nj_max. With that version, the code worked. So it looks like something introduced after that commit may have broken or interfered with the fix. |
And it should, but you should now be able to find a meaningful error message in your output file if you set
I guess by original fix you mean manually increasing nj_max = 131072;? Ideally, one would like to have |
|
Oh, I probably should have read this more carefully. My bad. Thanks! |
Trying to fix #1208, but not there yet, i.e. this will compile but not display a meaningful error message like "Hey, you have inserted too many stars, with respect to the Sapporo Light limit of$2^{17}=131,072$ ".
More specifically, Erwan's script will run flawlessly with$<2^{17}$ stars, but yield
with$2^{17} + 1$ stars.
This MR aims to propagate nj_max to "higher levels", i.e. to PH4 such that the controlling Python script - Erwan's script - can access it.
Adding a line$131072$ but instead yields
print(f"{code.get_nj_max() = }, ")to that script should yieldI have tried to work around this, but I have not succeeded.
Perhaps @LourensVeen could shed some light on this?